package com.travelranking.converter;

import java.util.ArrayList;
import java.util.List;

import com.travelranking.entity.CityEntity;
import com.travelranking.pojo.City;

public class CityConverter {

	public static CityEntity toEntity(City pojo) {
		CityEntity entity = new CityEntity();
		entity.setId(pojo.getId());
		entity.setName(pojo.getName());
		entity.setCountry(CountryConverter.toEntity(pojo.getCountry()));
		return entity;
	}

	public static City toPojo(CityEntity entity) {
		City pojo = new City();
		pojo.setId(entity.getId());
		pojo.setName(entity.getName());
		pojo.setCountry(CountryConverter.toPojo(entity.getCountry()));
		return pojo;
	}

	public static List<City> toPojoList(List<CityEntity> entity) {
		List<City> result = new ArrayList<City>();
		if (entity != null) {
			for (CityEntity e : entity) {
				result.add(toPojo(e));
			}
		}
		return result;
	}
	
}
